package cn.wolfcode.shop.web.controller;

import cn.wolfcode.shop.domain.OrderInfo;
import cn.wolfcode.shop.domain.User;
import cn.wolfcode.shop.result.CodeMsg;
import cn.wolfcode.shop.result.Result;
import cn.wolfcode.shop.service.IOrderInfoService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by wolfcode-lanxw
 */
@Controller
@RequestMapping("/orders")
public class OrderController {
    @Reference
    private IOrderInfoService orderInfoService;
    @RequestMapping("/getOrderDetail")
    @ResponseBody
    public Result<OrderInfo> getDetail(User user, String orderNo){
        if(user==null){
            return Result.error(CodeMsg.LOGIN_INVAILD);
        }
        OrderInfo orderInfo = orderInfoService.getOrder(orderNo);
        if(!orderInfo.getUserId().equals(user.getId())){
            return Result.error(CodeMsg.ILLEGAL_OP);
        }
        return Result.success(orderInfo);
    }
}
